package cn.gpnu.web.servlet;

import cn.gpnu.dao.TreePriceDao;
import cn.gpnu.dao.Treedao;
import cn.gpnu.dao.Userdao;
import cn.gpnu.domain.Tree;
import cn.gpnu.domain.TreePrice;
import cn.gpnu.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/select_tree")
public class select_tree extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id = Integer.parseInt(req.getParameter("id"));


        Userdao userdao = new Userdao();
        User user = userdao.select_user(id);

        Treedao dao = new Treedao();
        List<Tree> query = dao.select_tree(id);

        TreePriceDao treePriceDao = new TreePriceDao();
        List<TreePrice> treePrices = treePriceDao.select_price();
//        Userdao dao = new Userdao();
//        User user = dao.login(loginUser);
//        req.setAttribute("user",user);
//        req.getRequestDispatcher("/time.jsp").forward(req,resp);
        req.setAttribute("treePrices",treePrices);
        req.setAttribute("query",query);
        req.setAttribute("user",user);
        req.getRequestDispatcher("/JSP/shopping.jsp").forward(req,resp);
    }
}
